home *** CD-ROM | disk | FTP | other *** search
- Path: zeus.rbi.informatik.uni-frankfurt.de!gna1pc
- From: Ferber@zoology.uni-frankfurt.de (Michael Ferber)
- Newsgroups: comp.lang.c++
- Subject: problems reading binary data from file
- Date: Thu, 01 Feb 96 04:38:03 GMT
- Organization: Uni Frankfurt
- Message-ID: <4f4c4s$69q@zeus.rbi.informatik.uni-frankfurt.de>
- NNTP-Posting-Host: gna1pc.zoologys.uni-frankfurt.de
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- I have to read/write binary data from/to a file. Up to now I did this with
- fread and fwrite, but I want to switch to the fstream classes to avoid mixture
- of c and c++ code. Unfortunately the following code (the first part which
- writes to temp.bin) writes characters not binaries. What am I doing wrong???
- The second part (which writes to test.bin) works as expected. I use Watcom
- 10.0a. The code is a modiffied piece of the Watcom samples provided with the
- compiler.
- Thanks in advance
- Michael
-
- #include <fstream.h>
- #include <sys\stat.h>
- #include <sys\types.h>
- #include <fcntl.h>
- #include <stdio.h>
-
- void main( void )
- {
-
-
- int handle;
-
- handle = open( "temp.bin", ios::binary | ios::out , S_IRWXU );
- fstream test ( handle );
- for(int k = 1; k <=1000; k++)
- test << k;
-
- FILE *test2;
- test2 = fopen("test.bin", "w+b");
- for(int m = 1; m <=1000; m++)
- fwrite(&m, sizeof(m),1, test2);
- }
-
- ------------------------------------------------------------------------------------
- || Dr. Michael Ferber ||
- || Universitaet Frankfurt ||"science moves,
- || Zoologisches Institut || but slowly, slowly ......"
- || email: Ferber@zoology.uni-frankfurt.de || Tennyson
- ------------------------------------------------------------------------------------
-